package com.java.basis.map;


import java.util.Comparator;
import java.util.TreeMap;

/**
 * @author wangning
 * @create 2021-04-24 14:24
 */
public class TestTreeMap01 {
	public static void main(String[] args) {
		//新建集合
		TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
//				int n1 = o1.getName().compareTo(o2.getName());
				int n2 = o1.getAge() - o2.getAge();
				return n2;
			}
		});
		//1.添加元素
		Student s1 = new Student("送悟空", 100);
		Student s2 = new Student("猪八戒", 101);
		Student s3 = new Student("沙和尚", 102);

		treeMap.put(s1, "北京");
		treeMap.put(s2, "上海");
		treeMap.put(s3, "杭州");
		treeMap.put(new Student("沙和尚", 102), "广州");

		System.out.println(treeMap.size());
		System.out.println(treeMap.toString());

	}


}
